import { Component } from '@angular/core';
import {AlertController, IonicPage, NavController, NavParams } from 'ionic-angular';

/**
 * Generated class for the MerBuyAgentGoodsListPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-mer-buy-agent-goods-list',
  templateUrl: 'mer-buy-agent-goods-list.html',
})
export class MerBuyAgentGoodsListPage {
  goodList:any;
  msg:string='';
  whichone:string='';
  agentmsg:string='代理';
  food: string = 'store';
  foodtype: Array<{ ft: string }>;
  sumcount: number;
  money: any;
  imagesTH: Array<{ id: any, name: string, image: string, price: any, ft: string }>;
  showList: Array<{ id: any, name: string, image: string, price: any, ft: string }>;
  selectList: Array<{ id: any, name: string, img: string, count: number, price: any }>;
  name: string;
  addr: string;
  img: string;
  interest: string;
  collection: string;
  lastNum: number = 0;
  phone: string;
  private goodType:any;

  tel:any;

  constructor(public navCtrl: NavController, public navParams: NavParams,public alertCtrl: AlertController) {
    let item = this.navParams.get("data");
    this.whichone = this.navParams.get("whichone");
    console.log(this.whichone);
    this.selectList = [{id: 0, name: '', img: '', count: 0, price: 0.00}];
    this.name = item.name;
    this.img = item.src;
    this.addr = item.addr;
    this.phone = item.phone;
    //超市--商铺
    if(this.whichone==="market"){
      this.goodList=[
        {name:'推荐',id:'type0',goods:[
          {goodid:'001',goodname: '云南小粒咖啡', goodprice: '29.00', goodimg: 'assets/imgs/agent/kafei.jpg', sumbuy: '220',isbuy:false},
          {goodid:'002',goodname: '宣威火腿', goodprice: '489.00', goodimg: 'assets/imgs/agent/xuanwei.jpg', sumbuy: '101',isbuy:false},
          {goodid:'003',goodname: '普洱茶', goodprice: '120.00', goodimg: 'assets/imgs/agent/cha.jpg', sumbuy: '50',isbuy:false},
          {goodid:'004',goodname: '鲜花饼', goodprice: '66.00', goodimg: 'assets/imgs/agent/xianhuabing.jpg', sumbuy: '18',isbuy:false},
          {goodid:'005',goodname: '文山三七', goodprice: '352.00', goodimg: 'assets/imgs/agent/sanqi.jpg', sumbuy: '33',isbuy:false}
        ]},
        {name:'土特产',id:'type1',goods:[
          {goodid:'006',goodname: '木府吐司', goodprice: '29.00', goodimg: 'assets/imgs/agent/mufutusi.jpg', sumbuy: '220',isbuy:false},
          {goodid:'007',goodname: '深山野生菌', goodprice: '289.00', goodimg: 'assets/imgs/agent/yeshengjun.jpg', sumbuy: '101',isbuy:false}
        ]},
        {name:'优惠码',id:'type2',goods:[
          {goodid:'008',goodname: '全场9折优惠码', goodprice: '10', goodimg: 'assets/imgs/agent/优惠码.png', sumbuy: '220',isbuy:false},
        ]}
      ];
      this.goodType = [
        {name:'推荐',chosen:false},
        {name:'土特产',chosen:false},
        {name:'优惠码',chosen:false}
      ];
      this.goodType[0].chosen = true;
      this.tel=this.goodList[0].goods;
    }
    //餐饮--商铺
    if(this.whichone==="food"){
      this.goodList=[
        {name:'推荐',id:'type0',goods:[
          {goodid:'001',goodname: '黄焖鸡米线(大)', goodprice: '20.00', goodimg: 'assets/imgs/agent/huangmenji.jpg', sumbuy: '220',isbuy:false},
          {goodid:'002',goodname: '黄焖鸡米线(小)', goodprice: '20.00', goodimg: 'assets/imgs/agent/huangmenji.jpg', sumbuy: '220',isbuy:false}
        ]}
      ];
      this.goodType = [
        {name:'推荐',chosen:false}
      ];
      this.goodType[0].chosen = true;
      this.tel=this.goodList[0].goods;
    }
    //酒店--商铺
    if(this.whichone==="hotel"){
      this.goodList=[
        {name:'推荐',id:'type0',goods:[
          {goodid:'001',goodname: '标准间', goodprice: '99.00', goodimg: 'assets/imgs/agent/biaozhun.jpg', sumbuy: '220',isbuy:false}
        ]},
        {name:'温馨',id:'type1',goods:[
          {goodid:'002',goodname: '大床房', goodprice: '119.00', goodimg: 'assets/imgs/agent/dachuang.jpg', sumbuy: '120',isbuy:false}

        ]}
      ];
      this.goodType = [
        {name:'推荐',chosen:false},
        {name:'温馨',chosen:false}
      ];
      this.goodType[0].chosen = true;
      this.tel=this.goodList[0].goods;
    }
    //门票--商铺
    if(this.whichone==="ticket"){
      this.goodList=[
        {name:'推荐',id:'type0',goods:[
          {goodid:'001',goodname: '木府门票', goodprice: '41.00', goodimg: 'assets/imgs/agent/mufT.jpg', sumbuy: '156',isbuy:false},
          {goodid:'002',goodname: '印象丽江门票', goodprice: '60.00', goodimg: 'assets/imgs/agent/yinxiangT.jpg', sumbuy: '200',isbuy:false},
          {goodid:'003',goodname: '虎跳峡门票', goodprice: '15.00', goodimg: 'assets/imgs/agent/hutiaoT.jpg', sumbuy: '310',isbuy:false}
        ]}
      ];
      this.goodType = [
        {name:'推荐',chosen:false}
      ];
      this.goodType[0].chosen = true;
      this.tel= this.goodList[0].goods;
    }

  }

  buy(good){
    if(!good.isbuy)
      this.msg='确定';
    else this.msg='取消';
    let confirm = this.alertCtrl.create({
      title: good.goodname,
      message:  this.msg+'代购这件商品么？',
      buttons: [
        {
          text: '取消',
          handler: () => {
            console.log('Disagree clicked');
          }
        },
        {
          text: '确定',
          handler: () => {
            if(this.whichone==='ticket'){
              if(good.isbuy){
                good.sumbuy--;
              }else {
                good.sumbuy++;
              }
              good.isbuy = !good.isbuy;
            }

          }
        }
      ]
    });
    confirm.present();
  }
    showGoods(i){
      this.goodType[this.lastNum].chosen = false;
      this.lastNum = i;
      this.goodType[i].chosen = true;
      for(let j=0;j<this.goodList.length;j++){
        if(this.goodList[j].id==='type'+i){
          this.tel=this.goodList[j].goods;
        }
      }
    }
  ionViewDidLoad() {
    console.log('ionViewDidLoad MerBuyAgentGoodsListPage');
  }

  /**
   * 跳转至结算页面
   */
  Settlement(){
    this.navCtrl.push('FoodOrderPage');
  }

}
